import cv2
import pytesseract
from matplotlib import pyplot as plt

#pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

img1 = cv2.imread("D:/temp/pic/test/ocr_02.png")

# 转换为灰度图并进行二值化
gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

# 使用Otsu's方法自动寻找最佳阈值
_, binary = cv2.threshold(gray, 170, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

plt.imshow(binary)
plt.show()


text = pytesseract.image_to_string(binary, lang="eng+chi_sim")
print(text)
